<?php 
/* Script to display the comments for a client*/
if (!$_GET['page']) {
	include_once("../functions/functions.php");
	//Apply the style sheet
	echo "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../commentsformat.css\">";
	echo "<style>body {margin:3; padding:0;)</style>";
	echo "</head>";
	echo "<p align=\"right\"><a href=\"../index.php?page=comment_view&clientID=" . $HTTP_GET_VARS['clientID'] . "\" target=\"_top\"><font size=\"2\" color=\"blue\">Maximise View</font></a></p>";
}
else {
	echo "<h1>Client Comments</h1>";
}


//Store the post variables into local variables
$clientId = $HTTP_GET_VARS['clientID'];

//Construct query to get comments and execute the query
$sql = "SELECT * FROM `er_Comments` WHERE client_id=$clientId ORDER BY rank='Noteworthy', rank='Important' , rank='Very Important'";

$row = r_db($sql);

//Variable to store the rank temporarily for comparing on each loop
$tempRank = '';
//Counter variable to increment each time on looping
$i = 0;

//Print the table
echo "<table width=\"100%\">";

//Loop in the result set
while ($result = mysql_fetch_array($row))
{
	//Check to see the if the new record has the same rank as previous one for grouping purposes.
	if ($tempRank != $result[3] || empty($tempRank))
	{
		$tempRank = $result[3];
		echo "<tr>";
		echo "<td colspan=\"2\">";
		if ($i > 0) {
			echo "<br />";
		}
		echo "<font size=5><b>Rank - $tempRank</b></font><hr></td>";
		echo "</tr>";
		$i = 0;
	}//if ($tempRank != $result[3] || empty($tempRank))
	
	echo "<tr>";
	//Convert the comment date in English format
	$commentDate = $result[2];
	$commentDateAmerican=explode("-",substr($commentDate,0,10));
	$day=$commentDateAmerican[0];
	$month=$commentDateAmerican[1];
	$year=$commentDateAmerican[2];
	$commentDateEnglish=$year."/".$month."/".$day;
	
	//Print the comments date in English format
	//echo "<td valign=\"top\" bgcolor=". row_color($i) . " width=\"10%\"> $commentDateEnglish</td>";
	//Print comments 
	echo "<td bgcolor=". row_color($i) . " width=\"90%\"><font size=3><b>$result[1] </b></font></td>";
	echo "</tr>";
	$i++;
	
}
if ($i == 0) {
	echo "This client has no comments.";
}
echo "</table>";

?>